package com.itheima.controller;

import com.itheima.domain.EmpQueryParam;
import com.itheima.domain.PageResult;
import com.itheima.domain.Result;
import com.itheima.domain.StudentsQueryParam;
import com.itheima.domain.pojo.Students;
import com.itheima.service.StudentsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RequestMapping("/students")
@RestController
@Slf4j
public class StudentController {
    @Autowired
    private StudentsService studentService;
    //查询
//    @GetMapping
//    public Result StudentsLists() {
//        List<Students> studentsList = studentService.studentlists();
//                return Result.success(studentsList);
//    }





//分页查询
    @GetMapping
    public Result StudentsList(StudentsQueryParam studentsQueryParam) {
        PageResult pageResult = studentService.StudentsList(studentsQueryParam);
        return Result.success(pageResult);
    }


    //删除
    @DeleteMapping("{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        studentService.delete(ids);
        return Result.success();
    }


    //添加
    @PostMapping
    public Result save(@RequestBody Students students) {
        studentService.save(students);
        return Result.success();
    }



    //修改
      //数据回显，根据id查询
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) {
        Students students = studentService.selectByStudentId(id);
        return Result.success(students);
    }
//修改
    @PutMapping
    public Result update(@RequestBody Students students) {
        studentService.update(students);
        return Result.success();
    }

    //违纪处理
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id, @PathVariable Integer score) {
        studentService.violation(id, score);
        return Result.success();
    }
}
